package com.bangdream.michelia.utils;

import java.io.File;
import java.text.DecimalFormat;

/**
 * Created by Administrator on 2017/5/17.
 */

public class FileUtil {
    //需要创建的文件夹
    public static final File LocalPath = new File(PublicUtil.LocalPath);
    public static final File LocalPathImageCache = new File(LocalPath+PublicUtil.LocalImageCachePath);
    public static final File LocalPathImage = new File(LocalPath+PublicUtil.LocalImagePath);
    public static final File LocalPathVideo = new File(LocalPath+PublicUtil.LocalVideoPath);
    public static final File LocalPathVoice = new File(LocalPath+PublicUtil.LocalVoicePath);
    public static final File LocalPathDown = new File(LocalPath+PublicUtil.LocalDownLoadPath);
    public static final File[] LocalPathFiles = {LocalPath,LocalPathImageCache,LocalPathImage,LocalPathVideo,LocalPathVoice,LocalPathDown};
    //public static final File[] LocalPathFiles = {LocalPath};
    private static final String TAG = "FileUtil";

    //初始化需要用到的文件夹
    public static void CreateFile()
    {
        for(int i = 0;i<LocalPathFiles.length;i++) {
            MyLog.e(TAG,LocalPathFiles[i].toString());
            if (!LocalPathFiles[i].exists()) { //如果该文件夹不存在，则进行创建
                LocalPathFiles[i].mkdirs();//创建文件夹
                MyLog.e(TAG,"创建");
            }
            else
            {
                MyLog.e(TAG,"存在");
            }
        }
    }


    /**
     * 转换文件大小
     * */
    public static String FormentFileSize(long fileS) {
        DecimalFormat df = new DecimalFormat("#.00");
        String fileSizeString = "";
        if (fileS < 1024) {
            fileSizeString = df.format((double) fileS) + "B";
        } else if (fileS < 1048576) {
            fileSizeString = df.format((double) fileS / 1024) + "K";
        } else if (fileS < 1073741824) {
            fileSizeString = df.format((double) fileS / 1048576) + "M";
        } else {
            fileSizeString = df.format((double) fileS / 1073741824) + "G";
        }
        return fileSizeString;
    }
}
